home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 2741 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.0 KB

  1. Path: newshost.lanl.gov!tanmoy
  2. From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Please help ?!
  5. Date: 23 Jan 1996 16:23:20 GMT
  6. Organization: Los Alamos National Laboratory
  7. Message-ID: <TANMOY.96Jan23092320@qcd.lanl.gov>
  8. References: <4dm889$3hs@neptunus.pi.net> <4drnv1$cr@news.iag.net>
  9.     <4dvrk4$f2d@news.xs4all.nl>
  10. NNTP-Posting-Host: qcd.lanl.gov
  11. Mime-Version: 1.0
  12. Content-Type: text
  13. In-reply-to: Gertjan Klein's message of 22 Jan 1996 11:15:16 GMT
  14.  
  15. --text follows this line--
  16. In article <4dvrk4$f2d@news.xs4all.nl> Gertjan Klein
  17. <gklein@xs4all.nl> writes: 
  18. <snip>
  19.      int c = '\0';
  20.  
  21.      printf("Character %sfound in string.\n",
  22.          strchr(" /-", c) ? "" : "not ");
  23.      return 0;
  24.    }
  25.  
  26.      ... displays "Character found in string." whether I include the '\0'
  27.    or not. The basic question is, is the terminating zero regarded part of
  28.    the string here? My implementation's strchr() seems to imply it is, but
  29.    I'd like to know if this always the case. I couldn't find anything in
  30.    K&R2 about how strchr() behaves when the int to search for is 0. What's
  31.  
  32. The standard explicitly mentions that the termination '\0' is a part
  33. of the string.
  34.  
  35.    to keep it from first checking for the string terminator before doing
  36.    the compare? (In either case, including the '\0' in the string wouldn't
  37.  
  38. I probably didn't read enough of the message to figure this one out.
  39.  
  40.    make a difference, would it?)
  41.  
  42. No, it doesn't make a difference. The first '\0' terminates the `string'
  43. for the purposes of these library functions.
  44.  
  45. Cheers
  46. Tanmoy
  47.  
  48. --
  49. tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
  50. Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
  51. Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
  52. <http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
  53. internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
  54. fax: 1 (505) 665 3003   voice: 1 (505) 665 4733    [ Home: 1 (505) 662 5596 ]
  55.